/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.poker.zone;

import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import extension.game.poker.PokerFlag;
import extension.game.poker.PokerGame;
import extension.game.room.Game;
import extension.game.zone.GameZoneExtension;
import java.util.LinkedList;
import java.util.List;
import log.Debug;

/**
 *
 * @author daz
 */
public class ListTableInfoHandler extends BaseClientRequestHandler {

    @Override
    public void handleClientRequest(User user, ISFSObject params) {
        String groupName = params.getUtfString(Flag.GROUP_NAME);
        Debug.d("group name rec :" + groupName);
        PokerZoneExtension ext = (PokerZoneExtension) getParentExtension();
        PokerZoneResponse response = ext.getResponse();
        List<Room> listRooms = ext.getParentZone().getRoomListFromGroup(groupName);
        List<Integer> numberPlayerInRooms = new LinkedList<Integer>();
        List<String> listRoomNames = new LinkedList<String>();
        user.setProperty(Flag.GROUP_NAME, groupName);
        for (Room r : listRooms) {
            listRoomNames.add("#" + r.getName());
            Integer numberPlayers = (Integer) r.getProperty(PokerFlag.NUMBER_PLAYERS);
            if (numberPlayers == null) {
                numberPlayerInRooms.add(0);
            } else {
                numberPlayerInRooms.add(numberPlayers);
            }
        }
        List<Integer> levelMoney = new LinkedList<Integer>();
        for (int i = 0, l = GameZoneExtension.numberTable / GameZoneExtension.numberTablePerRooms; i < l; i++) {
            levelMoney.add(PokerGame.listLevelBet[i]);
        }
        int levelIndex = Integer.parseInt(groupName.substring(5)) - 1;
        response.sendListTable(levelMoney, levelIndex, numberPlayerInRooms, listRoomNames, groupName, user);
    }
}
